<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body style="background-color: #FFFAE3">
<div class="x-nav" style="height: 43px;background-color: #FFFAE3">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
          </span>
</div>
<div style="margin-top: 10px;margin-left: 115px;font-size: 18px;font-weight: bold;">
    <span id="span1">供应商报价</span>
</div>

<div id="formDiv" style="width: 500px;margin-left: 380px;border: 1px solid black;padding: 30px;padding-left: 0px;box-shadow:0px 0px 10px 5px rgba(0,0,0,0.2)">
    <form class="layui-form" action="" id="fromOrd">
        <input type="hidden" id="orderId">
        <div class="layui-form-item">
            <label class="layui-form-label">物资名称</label>
            <div class="layui-input-block" >
                <input id="materialName" type="text" name="title" lay-verify="title" readonly="readonly"  autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-block" >
                <input id="amount" type="text" name="title" lay-verify="title" readonly="readonly" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-block" >
                <input id="unitPrice" type="text" name="title" lay-verify="title" readonly="readonly" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">运杂费</label>
            <div class="layui-input-block">
                <input id="mixPrice" type="text" name="title" lay-verify="title"  placeholder="请输入运杂费"  autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">其它费用</label>
            <div class="layui-input-block">
                <input type="text" id="otherPrice" name="title" lay-verify="title" autocomplete="off" placeholder="请输入其它费用" class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
                <label class="layui-form-label">开始交货期</label>
            <div class="layui-input-block">
                <input type="date" id="startDate" name="title" lay-verify="title" autocomplete="off"  class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">结束交货期</label>
            <div class="layui-input-block">
                <input type="date" id="endDate" name="title" lay-verify="title" autocomplete="off" class="layui-input" style="background-color: #FFFAE3">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" onclick="BaoCun()" class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
                <button type="button" onclick="BaoCunFll()" class="layui-btn" lay-submit="" lay-filter="demo1">全部物资报价完毕</button>
            </div>
        </div>
        <input id="ordersId" type="hidden">
    </form>
</div>
<table class="layui-hide" id="demo"  lay-filter="demo" style="background-color: #FFFAE3"></table>
</body>
<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#demo'  //html中渲染table的id
            , url: '/orders/Sel'   //后台获取数据集合的地址
            , cellMinWidth: 80
            ,  cols: [
                [
                    //表单显示的title以及返回的需要显示的数据，field值与获取集合中的类的字段名一致。
                    {title: '选择', toolbar: "#checkbox",type:'radio', align: 'center'}
                    , {field: 'id', title: '序号', align: 'center'}
                    , {field: 'orderNum', title: '需求计划编号', align: 'center'}
                    , {field: 'materialCode', title: '物资编码', align: 'center'}
                    , {field: 'materialName', title: '物资名称', align: 'center'}
                    , {field: 'amount', title: '数量', align: 'center'}
                    , {field: 'unitPrice', title: '单价', align: 'center'}
                    , {field: 'status', title: '报价状态', align: 'center'}
                    // , {field: 'orderId', title: 'id', align: 'center',hide:true}

                ]
            ]
        });

        table.on('radio(demo)', function(obj){
            $(':input','#fromOrd')
                .not(':button, :submit, :reset, :hidden')
                .val('')
                .removeAttr('checked')
                .removeAttr('selected');
            var data = obj.data;
            if(data.status=="未报价"){
                $("#materialName").val(data.materialName);
                $("#amount").val(data.amount);
                $("#unitPrice").val(data.unitPrice);
                $("#ordersId").val(data.id);
            }else{
                $.ajax({
                    url: "/Quote/SelById",
                    data:{
                        "id":data.id
                    },
                    type: "GET",
                    success: function (result) {
                        $("#materialName").val(result.materialName);
                        $("#amount").val(result.amount);
                        $("#unitPrice").val(result.unitPrice);
                        $("#mixPrice").val(result.mixPrice);
                        $("#otherPrice").val(result.otherPrice);
                        $("#startDate").val(result.startDate);
                        $("#endDate").val(result.endDate);
                        $("#ordersId").val(result.orderId);
                    }
                });
            }
        });
    })
    function BaoCun(){
        var materialName=$("#materialName").val();
        var amount=$("#amount").val();
        var unitPrice=$("#unitPrice").val();
        var mixPrice=$("#mixPrice").val();
        var otherPrice=$("#otherPrice").val();
        var startDate=$("#startDate").val();
        var endDate=$("#endDate").val();
        var orderId=$("#ordersId").val();
        $.ajax({
             url: "/Quote/update",
             data:{
                 "materialName":materialName,
                 "amount":amount,
                 "unitPrice":unitPrice,
                 "mixPrice":mixPrice,
                 "otherPrice":otherPrice,
                 "startDate":startDate,
                 "endDate":endDate,
                 "orderId":orderId
             },
             type: "GET",
             success: function (result) {
                 location.reload();
             }
        });
    }
</script>
</html>